﻿using NServiceBus;
using System.Collections.Generic;
using System.Reflection;
using NServiceBus.ObjectBuilder;
using StructureMap;
using NServiceBus.Saga;


namespace Subscriber1
{
/*    class EndpointConfig : IConfigureThisEndpoint, AsA_Server
    {
        
    }*/

    class EndpointConfig : IConfigureThisEndpoint, IWantCustomInitialization
    {

        private StructureMap.IContainer _container;

        private IList<Assembly> assemblies = new List<Assembly>
                                                 {
                                                     Assembly.Load("MyMessages"),
                                                     typeof(EndpointConfig).Assembly, 
                                                     Assembly.Load("NServiceBus"),
                                                     Assembly.Load("NServiceBus.Core"),
                                                     Assembly.Load("NServiceBus.Host")
                                                 };

        public void Init()
        {
            ObjectFactory.Initialize(x => x.AddRegistry<SagaRegistry>());
            _container = ObjectFactory.Container;

            NServiceBus.Configure c = NServiceBus.Configure.With()
                .StructureMapBuilder(_container)
                .XmlSerializer()
                .MsmqSubscriptionStorage()
                .MsmqTransport()
                    .IsTransactional(true)
                    .PurgeOnStartup(true)
                .UnicastBus()
                    .LoadMessageHandlers()
                .Sagas()
                .SetSagaPersister(_container);

            IBuilder b = c.Builder;


        }
    }
}
